Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow $options['fieldList'] to be mangled/modified inside beforeValidate(). #957

Closed
wants to merge 1 commit into from

Conversation

bar
Copy link
Contributor

@bar bar commented Nov 13, 2012

Right now, ModelValidator::errors() triggers ModelValidator::_triggerBeforeValidate() with a copy of $options.

Later, ModelValidator::_triggerBeforeValidate() dispatches an event with those options, but if modified inside Model::beforeValidate() they are never updated inside ModelValidator::errors(), where actual validation occurs.

This is handy when needing to update $fieldList after a Model::save() is triggered.

@lorenzo
Copy link
Member

lorenzo commented Nov 13, 2012

We will need a test or this and one that involves behaviors

@bar
Copy link
Contributor Author

bar commented Nov 13, 2012

Roger, I'll do that.

@@ -247,7 +247,7 @@ public function validateMany(&$data, $options = array()) {
* @see ModelValidator::validates()
*/
public function errors($options = array()) {
if (!$this->_triggerBeforeValidate($options)) {
if (!$this->_triggerBeforeValidate(&$options)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from: http://php.net/manual/en/language.references.pass.php

There is no reference sign on a function call - only on function definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ceeram! you are right.

@ADmad
Copy link
Member

ADmad commented Nov 13, 2012

"Call-time pass-by-reference" errors 😄

@bar bar closed this Nov 13, 2012
@bar
Copy link
Contributor Author

bar commented Nov 13, 2012

This can't be done this way, as @ceeram correctly states, the reference sign should be set in the function definition, and to achieve this, CakeEvent should also pass its $data parameter always as a reference.

Maybe it is "the way" but its more complicated than this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants